package common.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.BagEvent;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.events.ListEvent;
	import lz.controls.managers.TipsManager;

	/**
	 *物品显示item 通用 
	 * @author lake
	 * 
	 */	
	public class GoodsItem extends IconItem
	{
		/**
		 *是否锁定状态 
		 */		
		protected var _isLock 		:Boolean;
		/**
		 *锁元件 
		 */		
		protected var lockMc		:MovieClip;
		/**
		 *选中状态 
		 */		
		protected var selectMc		:MovieClip;
		/**
		 *图像容器 
		 */		
		protected var container	:MovieClip;
		/**
		 *球员底色 
		 */		
		protected var colorBg		:MovieClip;
		/**
		 *球衣底色 
		 */		
		protected var clothColorBg :MovieClip;
		/**
		 *背景skin 
		 */		
		protected var bgSkin 		:MovieClip;
		/**
		 * 是否显示选中边框
		 */		
		public var isShowSelect	:Boolean = true;
		
		public function GoodsItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			if(value != null && value == _data)
			{
				return;
			}
			_data = value;
			var goodsVo :GoodsVo 		= value;
			DisplayObjectUtil.removeAllChildren(container);
			if(colorBg && colorBg.parent)
			{
				colorBg.parent.removeChild(colorBg);
			}
			if(clothColorBg && clothColorBg.parent)
			{
				clothColorBg.parent.removeChild(clothColorBg);
			}
			if(goodsVo)
			{
				if(goodsVo.type == GoodsType.PLAYERCARD)
				{
					container.addChild(colorBg);
					colorBg.y = -0.5;
					colorBg.x = -0.7;
					colorBg.gotoAndStop(goodsVo.color);
				}
				else if(goodsVo.type == GoodsType.TEAMCLOTH)
				{
					if(clothColorBg)
					{
						container.addChild(clothColorBg);
						clothColorBg.y = -0.5;
						clothColorBg.x = -0.7;
						clothColorBg.gotoAndStop(goodsVo.color);
					}
				}
				else
				{
					
				}
				var bitmapData :BitmapData 	= goodsVo.bitmapData;
				var bitmap :Bitmap = new Bitmap(bitmapData);
				container.addChild(bitmap);
				addEvtListener();
			}
			else
			{
				removeEvtListener();
			}
		}
		/**
		 * 选择
		 * 
		 */		
		override public function select():void
		{
			if(selectMc && isShowSelect)
			{
				this.addChild(selectMc);
			}
		}
		/**
		 * 
		 * 去除选择
		 */		
		override public function unSelect():void
		{
			if(selectMc && selectMc.parent)
			{
				selectMc.parent.removeChild(selectMc);
			}
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		override public function initUI(view:Object=null):void
		{
			bgSkin = Reflection.createInstance("com.liangzhong.ui.res.PropBg");
			bgSkin.bg.width = 54;
			bgSkin.bg.height = 55;
			container = bgSkin.container;
			container.x = 2;
			container.y = 2.35;
			this.addChild(bgSkin);
			selectMc = Reflection.createInstance("com.football.module.bag.SelectSkin");
			colorBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
			clothColorBg = Reflection.createInstance("com.lz.res.ClothColorBg");
			this.mouseChildren = false;
		}
		/**
		 * 添加事件
		 * 
		 */		
		override public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.addEventListener(MouseEvent.CLICK,onClickHandler);
			this.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		override protected function onOverHandler(e :MouseEvent):void
		{
			if(_data == null)return;
			if(_data.type == GoodsType.PLAYERCARD)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPS,_data,15,15,false,true);
			}
			else
			{
				TipsManager.show(TipsConst.BASETIPS,{tip:_data.tipsInfo},15,15,false,true);
			}
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		override protected function onOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 * 点击 
		 * @param e
		 * 
		 */		
		override protected function onClickHandler(e :MouseEvent):void
		{
			if(_data == null)
			{
				return;
			}
			this.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK,true,false,-1,-1,-1,_data));
		}
		/**
		 *双击使用 
		 * @param e
		 * 
		 */		
		protected function onDoubleClickHandler(e :MouseEvent):void
		{
			
		}
		/**
		 * 删除事件
		 * 
		 */		
		override public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.removeEventListener(MouseEvent.CLICK,onClickHandler);
			this.removeEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 销毁
		 * 
		 */		
		override public function destroyView():void
		{
			super.destroyView();
			removeEvtListener();
			bgSkin = null;
			_data = null;
		}
	}
}